import {reactive} from 'vue'

const dataList = reactive([
    {
        id: 1,
        name: 'Tom1',
        address: '地址111111111111',
    }
]);


export function list(params) {

    console.log(params)

    const start = (params.page - 1) * params.page_size
    const end = (params.page - 1) * params.page_size + params.page_size

    console.log(start, end)
    console.log(dataList.slice(start, end))

    return new Promise((resolve, reject) => {
        setTimeout(() => {

            const tableData = {
                count: (dataList.length),
                list: dataList.slice(start, end),
            };

            resolve(tableData)
        }, 500);
    })
}

export function add(params) {

    return new Promise((resolve, reject) => {

        params['id'] = dataList.length + 1;
        dataList.push(params)
        resolve()
    })
}

export function edit(params) {

    return new Promise((resolve, reject) => {

        dataList[params['id'] - 1] = params
        resolve()
    })
}

export function del(id) {

    return new Promise((resolve, reject) => {

        dataList.splice(id - 1, 1)
        resolve()
    })
}